#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main() {
    int arr1[1000] = { 0 };
    int arr2[1000] = { 0 };
    int m, n;
    scanf("%d ", &m);
    scanf("%d", &n);
    for (int i = 0; i < m; i++) {
        scanf("%d", &arr1[i]);
    }

    for (int i = 0; i < n; i++) {
        scanf("%d", &arr2[i]);
    }

    int* p1 = arr1;
    int* p2 = arr2;
    int arr3[2000] = { 0 };
    int* p3 = arr3;
    int* cur = arr3;
    int count1 = 0, count2 = 0, count3 = 0;
    while (count1 <m && count2 < n) {
        if (*p1 < *p2) {
            *cur = *p1;
            cur++;
            p1++;
            count1++;
        }
        else {
            *cur = *p2;
            cur++;
            p2++;
            count2++;
        }
        count3++;
    }
    
    int a = m - count1;
    int b = n - count2;
    if (count1 <m) {
        while (count3--) {
            printf("%d ", *p3);
            p3++;
        }
        while (a--) {
            printf("%d ", *p1);
            p1++;

        }
    }

    if (count2 < n) {
        while (count3--) {
            printf("%d ", *p3);
            p3++;
        }
        while (b--) {
            printf("%d ", *p2);
            p2++;
        }
    }

    return 0;
}